package com.vhall.component.controller.watchlimit;

import com.alibaba.fastjson.JSONObject;
import com.vhall.component.controller.watchlimit.facade.WatchLimitConsoleFacade;
import com.vhall.component.entity.watchlimit.vo.*;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.framework.common.exception.BusinessException;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.plugin.common.exception.BizErrorCode;
import com.vhall.component.service.watchlimit.WatchLimitConsoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author lsl
 * @since 2021/6/25
 */
@VhallComponent
public class WatchLimitConsoleController implements WatchLimitConsoleFacade {

    @Autowired
    private WatchLimitConsoleService watchLimitConsoleService;

    @Override
    @TokenAuth
    public JSONObject getWatchLimit(GetWatchLimitVO reqVO) {
        return watchLimitConsoleService.getWatchLimit(reqVO);
    }

    @Override
    @TokenAuth
    public JSONObject setWatchLimit(SetWatchLimitVO reqVO) {
        if (reqVO.getLimitType() == null) {
            throw new BusinessException(BizErrorCode.BIZ_INVALID_PARAM);
        }
        return watchLimitConsoleService.setWatchLimit(reqVO);
    }

    @TokenAuth
    @Override
    public WhiteUserListRespVO getWhitelist(WhiteListVO reqVO) {
        return watchLimitConsoleService.getWhitelist(reqVO);
    }

    @Override
    @TokenAuth
    public List<WhiteUserVO> searchWhitelist(SearchWhiteListVO reqVO) {
        return watchLimitConsoleService.searchWhitelist(reqVO);
    }

    @Override
    @TokenAuth
    public Integer delWhite(DelWhiteListVO reqVO) {
        return watchLimitConsoleService.delWhite(reqVO);
    }

    @Override
    @TokenAuth
    public JSONObject uploadWhitelist(UploadWhiteListNewVO reqVO) {
        UploadWhiteListVO newReqVO = new UploadWhiteListVO();
        BeanUtils.copyProperties(reqVO, newReqVO);
        MultipartFile document = reqVO.getDocument();
        return watchLimitConsoleService.uploadWhitelist(newReqVO, document);
    }

    @Override
    public JSONObject apply(ReplyVO reqVO) {
        return watchLimitConsoleService.apply(reqVO);
    }

}
